package doughnut.xc.Demo;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileOutputStream;

/**
 * POI基本的导入导出
 */
public class POIDemo1 {
    public static void main(String[] args) throws Exception {
        // 操作低版本api
        // String fileName = "D://demo.xls";
        // 创建一个全新的工作簿
        // Workbook workbook = new HSSFWorkbook();

        // 操作高版本api
        String fileName = "D://demo.xlsx";
       // 创建一个全新的工作簿
        Workbook workbook = new XSSFWorkbook();
        // 创建了一个全新的工作表
        Sheet sheet = workbook.createSheet();
        // 第一行
        Row row = sheet.createRow(0);
        row.createCell(0).setCellValue("姓名");
        row.createCell(1).setCellValue("年龄");
        // 第二行
        Row row2 = sheet.createRow(1);
        row2.createCell(0).setCellValue("张三");
        row2.createCell(1).setCellValue("20");

        FileOutputStream fileOutputStream = new FileOutputStream(fileName);
        workbook.write(fileOutputStream);
        fileOutputStream.close();
        workbook.close();
    }
}
